<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/category.png" alt="" /><?php echo $heading_title; ?></h1>
      <div class="buttons">
        <a onclick="location = '<?php echo $insert; ?>'" class="button"><?php echo $button_insert; ?></a>
        <a onclick="$('form').submit();" class="button"><?php echo $button_submit; ?></a>
      </div>
    </div>
    <div class="content">
      <form action="<?php echo $updateSortOrder; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
              <td class="left" style="width: 10%">id</td>
              <td class="left" style="width: 25%"><?php echo $column_name; ?></td>
              <td class="left" style="width: 25%"><?php echo $column_display_name; ?></td>
              <td class="left" style="width: 10%"><?php echo $column_sort_order; ?></td>
              <td class="left" style="width: 10%"><?php echo $column_status; ?></td>
              <td class="right" style="width: 20%"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
          	<tr class="filter">
              <td style="width: 10%"><input type="text" name="filter_category_id" value="<?php echo $filter_category_id; ?>" size="11"/></td>
              <td style="width: 25%"></td>
              <td style="width: 25%"></td>
              <td style="width: 10%"></td>
              <td style="width: 10%"></td>
              <td align="right" style="width: 20%"><a onclick="filter();" class="button"><?php echo $button_filter; ?></a></td>
            </tr>
            <?php if ($categories) {  foreach ($categories as $category) { ?>
            <tr>
              <?php if ($category['child']) { ?>
              <td class="left" style="width: 10%" onclick="showOrHideChild(this);"><img src="view/image/add.png"><?php echo $category['category_id']; ?></td>
              <?php }else{ ?>
              <td class="left" style="width: 10%"><?php echo $category['category_id']; ?></td>
              <?php } ?>
              <td class="left" style="width: 25%"><?php echo $category['name']; ?></td>
              <td class="left" style="width: 25%"><?php echo $category['display_name']; ?></td>
              <td class="left" style="width: 10%"><input type="text" name="category[<?php echo $category['category_id']; ?>][sort_order]" value="<?php echo $category['sort_order']; ?>" size="3"/></td>
              <td class="left" style="width: 10%"><?php echo $category['status']; ?></td>
              <td class="right" style="width: 20%"><?php foreach ($category['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php if ($category['child']) { ?>
            <tr class="categoryLevel2">
              <td colspan="6"><table class="list" style="padding:0px;margin:0px;"><tbody>
              	<?php foreach ($category['child'] as $catechild1) { ?>
	            <tr>
	              <?php if ($catechild1['child']) { ?>
	              <td class="left" style="width: 10%" onclick="showOrHideChild(this);"><img src="view/image/add.png"><?php echo $catechild1['category_id']; ?></td>
	              <?php }else{ ?>
	              <td class="left" style="width: 10%"><?php echo $catechild1['category_id']; ?></td>
	              <?php } ?>
	              <td class="left" style="width: 25%"><?php echo $catechild1['name']; ?></td>
	              <td class="left" style="width: 25%"><?php echo $catechild1['display_name']; ?></td>
	              <td class="left" style="width: 10%"><input type="text" name="category[<?php echo $catechild1['category_id']; ?>][sort_order]" value="<?php echo $catechild1['sort_order']; ?>" size="3"/></td>
	              <td class="left" style="width: 10%"><?php echo $catechild1['status']; ?></td>
	              <td class="right" style="width: 20%"><?php foreach ($catechild1['action'] as $action1) { ?>
	                [ <a href="<?php echo $action1['href']; ?>"><?php echo $action1['text']; ?></a> ]
	                <?php } ?></td>
	            </tr>
	            <?php if ($catechild1['child']) { ?>
	            <tr class="categoryLevel3">
	              <td colspan="6"><table class="list" style="padding:0px;margin:0px;"><tbody>
		            <?php foreach ($catechild1['child'] as $catechild2) { ?>
		            <tr>
		              <td class="left" style="width: 10%"><?php echo $catechild2['category_id']; ?></td>
		              <td class="left" style="width: 25%"><?php echo $catechild2['name']; ?></td>
		              <td class="left" style="width: 25%"><?php echo $catechild2['display_name']; ?></td>
		              <td class="left" style="width: 10%"><input type="text" name="category[<?php echo $catechild2['category_id']; ?>][sort_order]" value="<?php echo $catechild2['sort_order']; ?>" size="3"/></td>
		              <td class="left" style="width: 10%"><?php echo $catechild2['status']; ?></td>
		              <td class="right" style="width: 20%"><?php foreach ($catechild2['action'] as $action2) { ?>
		                [ <a href="<?php echo $action2['href']; ?>"><?php echo $action2['text']; ?></a> ]
		                <?php } ?></td>
		            </tr>
		            <?php } ?>
		          </tbody></table></td>
		        </tr>
	            <?php } ?>
                <?php } ?>
              </tbody></table></td>
            </tr>
            <?php } ?>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="6"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=product/category&token=<?php echo $token; ?>';
	var filter_category_id = $('input[name=\'filter_category_id\']').attr('value');
	url += '&filter_category_id=' + encodeURIComponent(filter_category_id);
	location = url;
}
function showOrHideChild(obj){
	$cur = $(obj);
	$img = $($cur.children().get(0));
	$nextTr = $cur.parent().next();
	$isHide = $nextTr.css("display");
	if($isHide == "none"){
		$img.attr("src", "view/image/delete.png");
		$nextTr.show();
	}else{
		$img.attr("src", "view/image/add.png");
		$nextTr.hide();
	}
}
//--></script> 
<?php echo $footer; ?>